<?php 
class PhaseOrder extends Phase
{
	private $successfullCommands = array();
        private $invalidCommands = array();

        /**
         *
         * @param <array> $commands
         */
	function __construct($commands)
	{
            parent::__construct($commands);
	}
	
	public function checkCommands()
	{
            $tmp = array();
            foreach ($this->getCommand() as $command)
            {
                if ($command instanceof CommandMove) {
                    
                    $tmp[] = $command;
                    for($i = 0; $i < count($tmp); $i++)
                    {
                        if($command->getDestination() == $tmp[$i]->getDestination()) {
                            // ungueltigen Befehl im Array abspeichern
                            $this->invalidCommands[] = $tmp[$i];

                            // alten Wert aus temp. Array entfernen
                            $after   = array_splice($tmp, $i + 1);
                            $before  = array_splice($tmp, 0, $i);
                            $tmp = array_merge($before, $after);
                        }
                        // Uebrig gebliebene = Befehle
                        $this->successfullCommands = $tmp;
                    }
                }
            }
	}
}
?>